<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>holitdata-motormux-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     HDMMUX,              sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: holitdata-motormux-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * holitdata-motormux.h provides an API for the Holit Data Systems Motor MUX. This program</span>
<span class="comment"> * demonstrates how to use that API to control the motors attached to the MUX.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: Removed common.h from list of includes</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Holit Data Systems for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 14 February 2011</span>
<span class="comment"> * version 0.2</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="holitdata-motormux_8h.html" title="Holit Data Systems Motor MUX driver.">drivers/holitdata-motormux.h</a>&quot;</span>

task main () {
  <span class="keywordtype">long</span> encA  = 0;
  <span class="keywordtype">long</span> encB  = 0;
  <span class="keywordtype">long</span> encC  = 0;

  ubyte motorStatus = 0;
  <span class="keywordtype">string</span> motorAstatus;
  <span class="keywordtype">string</span> motorBstatus;
  <span class="keywordtype">string</span> motorCstatus;

  eraseDisplay();

  <span class="comment">// Initialise all the internal variables</span>
  <a name="a0"></a><a class="code" href="group__holitdata.html#ga535f096dd8eef8d1c86cd818eb165c92">HDMMUXinit</a>();

  <span class="comment">// Reset the encoders.  This can be done individually or all at once.</span>
  <span class="comment">// You should do this at the start of your program.</span>
  <a name="a1"></a><a class="code" href="group__holitdata.html#ga7879fffe542c0918c97d5b5cfb277c4e">HDMMotorEncoderResetAll</a>(HDMMUX);

  <span class="comment">// You can specify the type of braking that should be used when the motors</span>
  <span class="comment">// are sent the stop command.  The default is to use brake.</span>
  <a name="a2"></a><a class="code" href="group__holitdata.html#ga8bd10328a9988cae8a9b58956664804b">HDMMotorSetBrake</a>(<a name="a3"></a><a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12aabb4a3ab7f9b14ff00edd2f377e181bb">mmotor_S1_1</a>);
  <a name="a4"></a><a class="code" href="group__holitdata.html#ga9082ae983475e561df02ed09d4dfbe3a">HDMMotorSetFloat</a>(<a name="a5"></a><a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12ab0e5af6e8540895adbd0aa1598a8656b">mmotor_S1_2</a>);
  <a class="code" href="group__holitdata.html#ga9082ae983475e561df02ed09d4dfbe3a">HDMMotorSetFloat</a>(<a name="a6"></a><a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12a1a6efd1925ccf0df8fc68f75ed1d1a6e">mmotor_S1_3</a>);

  <span class="comment">// Specify a target for the motors to run to.  This can be number of</span>
  <span class="comment">// rotations, seconds or degrees (encoder count).  Rotations and seconds</span>
  <span class="comment">// may be specified in increments of 0.01.</span>
  <a name="a7"></a><a class="code" href="group__holitdata.html#ga23bc66bcc708a0242b9fd9ce14a74b7a">HDMMotorSetRotationTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12aabb4a3ab7f9b14ff00edd2f377e181bb">mmotor_S1_1</a>, 4.50);
  <a name="a8"></a><a class="code" href="group__holitdata.html#ga9001ade37d758427c5b6ee16fe8c2310">HDMMotorSetTimeTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12ab0e5af6e8540895adbd0aa1598a8656b">mmotor_S1_2</a>, 2.50);
  <a name="a9"></a><a class="code" href="group__holitdata.html#gacb9ca2a2a00494399d5a49b0e768a452">HDMMotorSetEncoderTarget</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12a1a6efd1925ccf0df8fc68f75ed1d1a6e">mmotor_S1_3</a>, 1000);

  <span class="comment">// Tell the motors to start moving.</span>
  <a name="a10"></a><a class="code" href="group__holitdata.html#ga494763eb03935fb7266a4b73e4670178">HDMMotor</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12aabb4a3ab7f9b14ff00edd2f377e181bb">mmotor_S1_1</a>, 50);
  <a class="code" href="group__holitdata.html#ga494763eb03935fb7266a4b73e4670178">HDMMotor</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12ab0e5af6e8540895adbd0aa1598a8656b">mmotor_S1_2</a>, 50);
  <a class="code" href="group__holitdata.html#ga494763eb03935fb7266a4b73e4670178">HDMMotor</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12a1a6efd1925ccf0df8fc68f75ed1d1a6e">mmotor_S1_3</a>, 50);

  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="comment">// Retrieve the motor-MUX&#39;s status info and encoder counts</span>
                <a name="a11"></a><a class="code" href="group__holitdata.html#gaf4c7a5f3640743090b2d360e7333ea2f">HDMMUXreadStatus</a>(HDMMUX, motorStatus, encA, encB, encC);

                <span class="comment">// Use the HDMMotorBusy() function to see if a motor is busy or idle.</span>
                motorAstatus = <a name="a12"></a><a class="code" href="group__holitdata.html#ga633cd6ad7e5682af6e0a3bfd9b793442">HDMMotorBusy</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12aabb4a3ab7f9b14ff00edd2f377e181bb">mmotor_S1_1</a>) ? <span class="stringliteral">&quot;busy&quot;</span> : <span class="stringliteral">&quot;idle&quot;</span>;
          motorBstatus = <a class="code" href="group__holitdata.html#ga633cd6ad7e5682af6e0a3bfd9b793442">HDMMotorBusy</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12ab0e5af6e8540895adbd0aa1598a8656b">mmotor_S1_2</a>) ? <span class="stringliteral">&quot;busy&quot;</span> : <span class="stringliteral">&quot;idle&quot;</span>;
                motorCstatus = <a class="code" href="group__holitdata.html#ga633cd6ad7e5682af6e0a3bfd9b793442">HDMMotorBusy</a>(<a class="code" href="group___m_m_u_x-common__h.html#gga11217de3dd0a7e4159c3578c1cdbba12a1a6efd1925ccf0df8fc68f75ed1d1a6e">mmotor_S1_3</a>) ? <span class="stringliteral">&quot;busy&quot;</span> : <span class="stringliteral">&quot;idle&quot;</span>;

                <span class="comment">// Display the info.</span>
                nxtDisplayTextLine(5, <span class="stringliteral">&quot;A: %5d (%s)&quot;</span>, encA, motorAstatus);
                nxtDisplayTextLine(6, <span class="stringliteral">&quot;B: %5d (%s)&quot;</span>, encB, motorBstatus);
                nxtDisplayTextLine(7, <span class="stringliteral">&quot;C: %5d (%s)&quot;</span>, encC, motorCstatus);
    wait1Msec(5);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: holitdata-motormux-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
